﻿/**************************************************************************
**
** This file is part of QSsh
**
** Copyright (c) 2012 LVK
**
** Contact: andres.pagliano@lvklabs.com
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
**************************************************************************/

#ifndef SECUREFILEUPLOADER_H
#define SECUREFILEUPLOADER_H

#include <QObject>
#include "sshremoteprocess.h"
#include "sftpchannel.h"
#include "sshconnection.h"
enum SSHCMD_TYPE {
    //SSH连接成功
    SSH_CONNECTED = 1,
    //SSH断开成功
    SSH_DISCONN = 2,
    //SSH开始传输文件
    SSH_FILESTART = 3,
    //SSH传输完毕
    SSH_FILEEND = 4,
    //SSH指令发送
    SSH_SENDCMD = 5,
    //SSH未建立连接
    SSH_SOCKETERRO = 6,
    //SFTP通道未建立
    SSH_SFTPERRO = 7,
    //文件未能下发
    SSH_FILEERRO = 8,
};
/// Very simple example to upload a file using FTPS
class SecureFileUploader : public QObject
{
    Q_OBJECT
public:

    explicit SecureFileUploader(QObject *parent = 0);
    ~SecureFileUploader();
    /// Uploads \a localFile to \a username@host:/dest using password \a passwd
    void upload(const QString &localFile, const QString &dest);
    //SSH连接
    void SSHconnect(QString,int,QString,QString);
    //SSH断开
    void SSHdisconnect();
signals:
    void sendsshres(int);
    void sendsshmsg(QString);
public slots:
    void Slot_sendSSHcmd(QString);
private slots:
    void onConnected();
    void onConnectionError(QSsh::SshError);
    void onChannelInitialized();
    void onChannelError(const QString &err);
    void onOpfinished(QSsh::SftpJobId job, const QString & error = QString());
    void onDisConnected();
    void dataReceived();
private:
    //QSsh::SshConnectionParameters params;
    QString m_localFilename;
    QString m_remoteFilename;
    QSsh::SftpChannel::Ptr m_channel;
    QSsh::SshConnection *m_connection;
    QSharedPointer<QSsh::SshRemoteProcess> shell;
    void parseDestination(const QString &dest);
};

#endif // SECUREFILEUPLOADER_H
